package com.chaoyi.controller.ifs;

import com.chaoyi.doman.koreanvideo.*;
import com.chaoyi.enums.ResultStatus;
import com.chaoyi.exception.ParameterException;
import com.chaoyi.service.KoreanVideoService;
import com.chaoyi.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import javax.validation.constraints.Pattern;
import java.util.List;
import java.util.Map;


/**
 * 韩国视频接口
 * @author xuanqicheng
 * @create 2018-11-上午10:28
 */
@Controller
@RequestMapping("/koreanVideo")
public class KoreanVideoIfsController {

    @Autowired
    private KoreanVideoService koreanVideoService;
    /**
     * 电影分类列表
     * @param koreanVideoClassificationQueryCondition
     * @return
     */
    @RequestMapping("getKoreanVideoClassificationList")
    @ResponseBody
    public ResultVo getVideoClassification(
            @Valid KoreanVideoClassificationQueryCondition koreanVideoClassificationQueryCondition,BindingResult bindingResul) {

        //验证请求参数是否合法
        checkParameter(bindingResul);

        List<KoreanVideoOutput> list = koreanVideoService.getVideoClassificationList(koreanVideoClassificationQueryCondition);

        return new ResultVo(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMessage(), list);
    }

    /**
     * 韩国电影在线影院列表
     * @return
     */
    @RequestMapping("getKoreanOnlineVideoList")
    @ResponseBody
    public ResultVo getKoreanOnlineVideoList(@Valid KoreanVideoQueryCondition koreanVideoQueryCondition,
                                             BindingResult bindingResul) {

        //验证请求参数是否合法
        checkParameter(bindingResul);

        List<KoreanOnlineVideoOutput> list = koreanVideoService.getKoreanOnlineVideoList(koreanVideoQueryCondition);

        return new ResultVo(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMessage(), list);
    }

    /**
     * 试看
     * @param id
     * @return
     */
    @RequestMapping("getTryToSee")
    @ResponseBody
    public ResultVo getTryToSee(String id) {

        Map<String,String> resultMap = koreanVideoService.getTryToSee(id);

        return new ResultVo(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMessage(), resultMap);
    }

    /**
     * 正片
     * @param id
     * @return
     */
    @RequestMapping("getSee")
    @ResponseBody
    public ResultVo getSee(String id) {


        Map<String,String> resultMap = koreanVideoService.getSee(id);

        return new ResultVo(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMessage(), resultMap);
    }
    private void checkParameter(BindingResult bindingResul) {
        if (bindingResul.hasErrors()) {

            throw new ParameterException(ResultStatus.PARAMETER_EXCEPTION_CODE.getCode(),
                    bindingResul.getFieldError().getDefaultMessage());
        }
    }


    /**
     * 正片
     * @param id
     * @return
     */
    @RequestMapping("getDetail")
    @ResponseBody
    public ResultVo getDetail(String id) {


        KoreanVideoDetailOutput koreanVideoDetailOutput= koreanVideoService.getDetail(id);

        return new ResultVo(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMessage(), koreanVideoDetailOutput);
    }

}
